
#include <stdio.h>
#include <syslog.h>
#include <stdarg.h>

#include "log.h"

void print_log( LogLevel_t level, const char * format, ...)
{
	va_list va;

	if ( !format )
		return;

	if ( !log_verbosity && level >= LOG_VERBOSE )
		return;

	va_start (va, format);
	if ( log_daemonized )
	{
		int flags = LOG_DAEMON;
		flags |= level == LOG_ERROR ? LOG_ERR : LOG_NOTICE;
		vsyslog (flags, format, va);
	}
	else
	{
		FILE *output = level == LOG_ERROR ? stderr : stdout;
		vfprintf (output, format, va); //OK
	}
	va_end (va);
}

void start_log ( char * name )
{
	openlog ( name , LOG_PID, LOG_DAEMON);
}

